package com.atguigu.gulimall.product.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program: gulimall
 * @description:
 * @author: 江天赐
 * @create: 2022-08-10 17:58
 */
@EnableConfigurationProperties(ThreadPoolConfigurationProperties.class)
@Configuration
public class MyThreadConfiguration {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigurationProperties pool) {
        return new ThreadPoolExecutor(pool.getCoresize(),
                pool.getMaxSize(),
                pool.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }
}
